namespace nDeveloper.VSS.DifferenceEngine
{
    using System;

    internal class DiffState
    {
        private int _length;
        private int _startIndex;
        private const int BAD_INDEX = -1;

        public DiffState()
        {
            this.SetToUnkown();
        }

        public bool HasValidLength(int newStart, int newEnd, int maxPossibleDestLength)
        {
            if ((this._length > 0) && (((maxPossibleDestLength < this._length) || (this._startIndex < newStart)) || (this.EndIndex > newEnd)))
            {
                this.SetToUnkown();
            }
            return (this._length != -2);
        }

        public void SetMatch(int start, int length)
        {
            this._startIndex = start;
            this._length = length;
        }

        public void SetNoMatch()
        {
            this._startIndex = -1;
            this._length = -1;
        }

        protected void SetToUnkown()
        {
            this._startIndex = -1;
            this._length = -2;
        }

        public int EndIndex
        {
            get
            {
                return ((this._startIndex + this._length) - 1);
            }
        }

        public int Length
        {
            get
            {
                if (this._length > 0)
                {
                    return this._length;
                }
                if (this._length == 0)
                {
                    return 1;
                }
                return 0;
            }
        }

        public int StartIndex
        {
            get
            {
                return this._startIndex;
            }
        }

        public DiffStatus Status
        {
            get
            {
                if (this._length > 0)
                {
                    return DiffStatus.Matched;
                }
                if (this._length == -1)
                {
                    return DiffStatus.NoMatch;
                }
                return DiffStatus.Unknown;
            }
        }
    }
}

